<?php /*a:3:{s:65:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\authgroups\index.html";i:1747733331;s:62:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\header.html";i:1747733208;s:61:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\style.html";i:1747733208;}*/ ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ERP</title>

    <link rel="stylesheet" href="/static/css/element-ui@2.15.14.css">
    <script src="/static/js/vue.js"></script>
    <script src="/static/js/element-ui@2.15.14.js"></script>
    <script src="/static/js/axios.js"></script>
    <script src="/static/js/qs.js"></script>
    <script src="/static/js/config.js"></script>
    <script src="/static/js/echart.js"></script>


    <style scoped>
        .el-select-dropdown {
        padding: 0;
        }
    </style>
    
<style>
    html,
    body,
    #app {
        padding: 0;
        margin: 0;
    }    
    #contenr{
        padding: 0;
        margin: 10px;
    }
</style>

<body>
    <div id="app"  v-cloak>
        <div id="contenr">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>权限组列表</el-breadcrumb-item>
        </el-breadcrumb>
        <br>
        <el-card >
            <div style="display: flex;align-items: center;justify-content: flex-start;">
                <el-form :inline="true" :model="searchForm" size="small"  ref="refsearchForm">                
                    <el-form-item label="权限组名称">
                        <el-input v-model="searchForm.title" placeholder="请输入权限组" clearable filterable></el-input>
                    </el-form-item>         
   
                    <el-form-item label="权限组状态">
                        <el-select v-model="searchForm.status" placeholder="请选择权限组状态" filterable clearable>
                            <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item> 
                        <el-button type="primary"  size="small" icon="el-icon-search" plain @click="getSearch" v-cloak>查询</el-button>
                    </el-form-item>            </el-form>
                
                <div style="margin-left: auto;margin-bottom: 20px;margin-right: 20px;" >
                        <el-button  type="primary"   @click="create" size="small"  icon="el-icon-edit" >添加权限组</el-button>       
                </div>
            </div>

            <el-table :data="tablelist"   style="width: 100%;margin-bottom: 20px;"  row-key="id"  border  :row-key="(row)=>row.key">
                <el-table-column   prop="title" label="权限组名称"> </el-table-column>   
           
                <el-table-column   prop="status"  label="权限组状态" width="390"> 
                    <template slot-scope="scope">
                        <el-switch style="display: block"  v-if="scope.
                        row.id !== 1" v-model="scope.row.status"  active-color="#13ce66" inactive-color="#ff4949" :inactive-value="0" :active-value="1" active-text="正常" inactive-text="关闭" @change="handleSwitchChange(scope.row)">
                        </el-switch>
                        <span v-if="scope.row.id ===1">
                            <el-tag type="success">正常</el-tag>
                         </span>
                    </template>                          
                </el-table-column>
                <el-table-column  fixed="right" label="操作" width="350">
                    <template v-slot="{row}">
                        <el-button type="primary"  plain icon="el-icon-edit" v-if="row.id !== 1" @click="editor(row)" >编辑 </el-button>        
                        <el-button type="success"  plain   icon="el-icon-edit"  v-if="row.id !== 1"  @click="purview(row)" >设置权限 </el-button>        
                        <el-button type="danger"  plain icon="el-icon-delete"  v-if="row.id !== 1"  @click="cancel(row.id)">删除</el-button>             
                    </template>
                </el-table-column>
            </el-table>

            <!-- page -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="searchForm.pagenum" :page-sizes="[20,50,100, 150, 300,500,1000,2000]"
                :page-size="searchForm.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>  
        </el-card>
        
        <!-- 修改编辑弹窗 -->
        <el-dialog :title="title" :visible.sync="ismenudialogVisible " width="600px" :close-on-click-modal="false">
            <el-form :inline="true" :model="createForm" size="mini"  :rules="isMenurules"  ref="refsearchForm"  :popper-append-to-body="false"  >              
               
                <el-form-item label-width="110px" prop="title" label="权限组名称">
                    <el-input v-model="createForm.title" placeholder="请输入权限组名称" style="width: 370px;"
                            clearable></el-input>
                </el-form-item>
                <el-form-item label-width="110px"  label="权限组状态">
                    <template   >                       
                        <el-radio-group v-model="createForm.status" style="margin-left: 10px;">
                            <el-radio :label="1" border>正常</el-radio>
                            <el-radio :label="0" border>关闭</el-radio>
                    </el-radio-group> 
                    </template>
                </el-form-item>      
                <div>                   
                    <el-form-item>
                        <el-button type="primary" @click="checkSubmits">确认</el-button>
                        <el-button type="primary" plain @click="close"> 取消</el-button>
                    </el-form-item>  
                </div>                 
            </el-form>
        </el-dialog>

            
    </div>

        <script>
            new Vue({
                el: '#app',
                data: function () {
                    return {  
                        status:[
                            {
                                value: 2,
                                label: '关闭'
                            },
                            {
                                value: 1,
                                label: '正常'
                            }
                        ],// 状态是否正常              
                
                        total:'',   //分页总页数      
                        tablelist:[],              
                        searchForm: {
                            title: '',
                            status: '',
                            pagenum: 1,
                            pagesize: 20,              
                        
                        },
                        editForm:{
                            status:'',
                            id:''
                        },
                        menu:[],
                        createForm:{
                            status:1,                
                            title:'',            
                        },
                        ismenudialogVisible: false, 
                        title:'',
                        isMenurules:{
                            title: [
                                { required: true, message: '请输入权限组名称', trigger: 'blur' }
                            ],
                            sort: [
                                { required: true, message: '请输入排序权重', trigger: 'blur' }
                            ],
                        }             
                        
                    }
                },
                mounted(){
                    this.getSearch()
                },
                methods: {        

                    async getDatalist() {
                        const res = await axios.post('/admin/authgroups/index', {params: this.searchForm})
                            if (res.status !== 1) {
                                return this.$message.error(res.info);
                            }
                        this.total = res.info.total
                        this.tablelist = res.info.list
                    },

                    //编辑
                    editor(row){         
                        this.title = '编辑权限组'
                        this.ismenudialogVisible = true
                        this.$set(this.createForm,'id',row.id);
                        this.$set(this.createForm,'title',row.title);    
                        this.$set(this.createForm,'status',row.status);                        
                    },
                    //添加权限
                    create(){
                        this.title = '添加权限组'
                        this.ismenudialogVisible = true
                        this.createForm.id = ''
                        this.createForm.status = 1         
                        this.createForm.title = ''        
                    },        
                    handleSizeChange(newSize) {
                        this.searchForm.pagesize = newSize
                        this.getDatalist()
                    },
                    handleCurrentChange(newPage) {
                        this.searchForm.pagenum = newPage
                        this.getDatalist()
                    },
                    handleSelectionChange(val) {
                        this.multipleSelection = val;
                    },
                
                    getSearch() {
                        this.searchForm.pagenum = 1
                        this.getDatalist()
                    },
                    //修改权限组的状态
                    handleSwitchChange(row) {
                        this.editForm.id = row.id
                        this.editForm.status = row.status  
                        this.$confirm('确认需要修改权限组的状态？', '提示', {
                                confirmButtonText: '确定修改',
                                cancelButtonText: '取消修改',
                                closeOnClickModal: false, // 禁用点击遮罩关闭弹窗
                                type: 'warning'
                            }).then(() => {
                                axios.post('/admin/authgroups/update_status', {params: this.editForm}).then(res => {
                                    if (res.status !== 1) {
                                        return this.$message.error(res.info);             
                                    }                    
                                    this.$message.success('修改成功');
                                    this.getDatalist()
                                }).catch(err => {
                                    console.log(err)
                                })
                            }).catch(() => {
                                this.getDatalist()
                                this.$message.info('已取消修改');
                            });
                    },
                    //确认提交修改
                    async checkSubmits(){
                        this.$refs.refsearchForm.validate(async valid => {
                            if (!valid) return;
                            let loading = this.$loading({
                                lock: true,
                                text: '数据加载中···',
                                spinner: 'el-icon-loading',
                                background: 'rgba(0, 0, 0, 0.7)'
                                });
                            axios.post('/admin/authgroups/create', {params: this.createForm}).then(res => {
                                loading.close()
                                if (res.status !== 1) {
                                    return this.$message.error(res.info);                  
                                }
                            
                                this.$message.success('操作成功');
                                this.ismenudialogVisible = false
                                this.getDatalist()
                            }).catch(err => {
                                console.log(err)
                            })
                        })
                    },
                    //删除
                    cancel($id){
                            this.$confirm('确认需要删除？', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                closeOnClickModal: false, // 禁用点击遮罩关闭弹窗
                                type: 'warning'
                            }).then(() => {
                                axios.post('/admin/authgroups/delete', {params: {id: $id}}).then(res => {
                                    if (res.status !== 1) {
                                        return this.$message.error(res.info);             
                                    }                    
                                    this.$message.success('删除成功');
                                    this.getDatalist()
                                }).catch(err => {
                                    console.log(err)
                                })
                            }).catch(() => {
                                this.$message.info('已取消');
                                });
                    },
                    //关闭弹窗
                    close(){
                        this.ismenudialogVisible=false  
                    },     
                    //设置权限
                    purview(row){
                        window.location.href = "/admin/authgroups/purview?id="+row.id+ "&title="+row.title
                    }
                }
            })
        </script>
    </body> 
</html>
